var JOURNAL = [{
        "events": ["carrot", "exercise", "weekend"],
        "squirrel": false
    },
    {
        "events": ["bread", "pudding", "brushed teeth", "weekend", "touched tree"],
        "squirrel": false
    },
    {
        "events": ["carrot", "nachos", "brushed teeth", "cycling", "weekend"],
        "squirrel": false
    },
    {
        "events": ["brussel sprouts", "ice cream", "brushed teeth", "computer", "weekend"],
        "squirrel": false
    },
    {
        "events": ["potatoes", "candy", "brushed teeth", "exercise", "weekend", "dentist"],
        "squirrel": false
    },
    {
        "events": ["brussel sprouts", "pudding", "brushed teeth", "running", "weekend"],
        "squirrel": false
    },
    {
        "events": ["pizza", "brushed teeth", "computer", "work", "touched tree"],
        "squirrel": false
    },
    {
        "events": ["bread", "beer", "brushed teeth", "cycling", "work"],
        "squirrel": false
    },
    {
        "events": ["cauliflower", "brushed teeth", "work"],
        "squirrel": false
    },
    {
        "events": ["pizza", "brushed teeth", "cycling", "work"],
        "squirrel": false
    },
    {
        "events": ["lasagna", "nachos", "brushed teeth", "work"],
        "squirrel": false
    },
    {
        "events": ["brushed teeth", "weekend", "touched tree"],
        "squirrel": false
    },
    {
        "events": ["lettuce", "brushed teeth", "television", "weekend"],
        "squirrel": false
    },
    {
        "events": ["spaghetti", "brushed teeth", "work"],
        "squirrel": false
    },
    {
        "events": ["brushed teeth", "computer", "work"],
        "squirrel": false
    },
    {
        "events": ["lettuce", "nachos", "brushed teeth", "work"],
        "squirrel": false
    },
    {
        "events": ["carrot", "brushed teeth", "running", "work"],
        "squirrel": false
    },
    {
        "events": ["brushed teeth", "work"],
        "squirrel": false
    },
    {
        "events": ["cauliflower", "reading", "weekend"],
        "squirrel": false
    },
    {
        "events": ["bread", "brushed teeth", "weekend"],
        "squirrel": false
    },
    {
        "events": ["lasagna", "brushed teeth", "exercise", "work"],
        "squirrel": false
    },
    {
        "events": ["spaghetti", "brushed teeth", "reading", "work"],
        "squirrel": false
    },
    {
        "events": ["carrot", "ice cream", "brushed teeth", "television", "work"],
        "squirrel": false
    },
    {
        "events": ["spaghetti", "nachos", "work"],
        "squirrel": false
    },
    {
        "events": ["cauliflower", "ice cream", "brushed teeth", "cycling", "work"],
        "squirrel": false
    },
    {
        "events": ["spaghetti", "peanuts", "computer", "weekend"],
        "squirrel": true
    },
    {
        "events": ["potatoes", "ice cream", "brushed teeth", "computer", "weekend"],
        "squirrel": false
    },
    {
        "events": ["potatoes", "ice cream", "brushed teeth", "work"],
        "squirrel": false
    },
    {
        "events": ["peanuts", "brushed teeth", "running", "work"],
        "squirrel": false
    },
    {
        "events": ["potatoes", "exercise", "work"],
        "squirrel": false
    },
    {
        "events": ["pizza", "ice cream", "computer", "work"],
        "squirrel": false
    },
    {
        "events": ["lasagna", "ice cream", "work"],
        "squirrel": false
    },
    {
        "events": ["cauliflower", "candy", "reading", "weekend"],
        "squirrel": false
    },
    {
        "events": ["lasagna", "nachos", "brushed teeth", "running", "weekend"],
        "squirrel": false
    },
    {
        "events": ["potatoes", "brushed teeth", "work"],
        "squirrel": false
    },
    {
        "events": ["carrot", "work"],
        "squirrel": false
    },
    {
        "events": ["pizza", "beer", "work", "dentist"],
        "squirrel": false
    },
    {
        "events": ["lasagna", "pudding", "cycling", "work"],
        "squirrel": false
    },
    {
        "events": ["spaghetti", "brushed teeth", "reading", "work"],
        "squirrel": false
    },
    {
        "events": ["spaghetti", "pudding", "television", "weekend"],
        "squirrel": false
    },
    {
        "events": ["bread", "brushed teeth", "exercise", "weekend"],
        "squirrel": false
    },
    {
        "events": ["lasagna", "peanuts", "work"],
        "squirrel": true
    },
    {
        "events": ["pizza", "work"],
        "squirrel": false
    },
    {
        "events": ["potatoes", "exercise", "work"],
        "squirrel": false
    },
    {
        "events": ["brushed teeth", "exercise", "work"],
        "squirrel": false
    },
    {
        "events": ["spaghetti", "brushed teeth", "television", "work"],
        "squirrel": false
    },
    {
        "events": ["pizza", "cycling", "weekend"],
        "squirrel": false
    },
    {
        "events": ["carrot", "brushed teeth", "weekend"],
        "squirrel": false
    },
    {
        "events": ["carrot", "beer", "brushed teeth", "work"],
        "squirrel": false
    },
    {
        "events": ["pizza", "peanuts", "candy", "work"],
        "squirrel": true
    },
    {
        "events": ["carrot", "peanuts", "brushed teeth", "reading", "work"],
        "squirrel": false
    },
    {
        "events": ["potatoes", "peanuts", "brushed teeth", "work"],
        "squirrel": false
    },
    {
        "events": ["carrot", "nachos", "brushed teeth", "exercise", "work"],
        "squirrel": false
    },
    {
        "events": ["pizza", "peanuts", "brushed teeth", "television", "weekend"],
        "squirrel": false
    },
    {
        "events": ["lasagna", "brushed teeth", "cycling", "weekend"],
        "squirrel": false
    },
    {
        "events": ["cauliflower", "peanuts", "brushed teeth", "computer", "work", "touched tree"],
        "squirrel": false
    },
    {
        "events": ["lettuce", "brushed teeth", "television", "work"],
        "squirrel": false
    },
    {
        "events": ["potatoes", "brushed teeth", "computer", "work"],
        "squirrel": false
    },
    {
        "events": ["bread", "candy", "work"],
        "squirrel": false
    },
    {
        "events": ["potatoes", "nachos", "work"],
        "squirrel": false
    },
    {
        "events": ["carrot", "pudding", "brushed teeth", "weekend"],
        "squirrel": false
    },
    {
        "events": ["carrot", "brushed teeth", "exercise", "weekend", "touched tree"],
        "squirrel": false
    },
    {
        "events": ["brussel sprouts", "running", "work"],
        "squirrel": false
    },
    {
        "events": ["brushed teeth", "work"],
        "squirrel": false
    },
    {
        "events": ["lettuce", "brushed teeth", "running", "work"],
        "squirrel": false
    },
    {
        "events": ["candy", "brushed teeth", "work"],
        "squirrel": false
    },
    {
        "events": ["brussel sprouts", "brushed teeth", "computer", "work"],
        "squirrel": false
    },
    {
        "events": ["bread", "brushed teeth", "weekend"],
        "squirrel": false
    },
    {
        "events": ["cauliflower", "brushed teeth", "weekend"],
        "squirrel": false
    },
    {
        "events": ["spaghetti", "candy", "television", "work", "touched tree"],
        "squirrel": false
    },
    {
        "events": ["carrot", "pudding", "brushed teeth", "work"],
        "squirrel": false
    },
    {
        "events": ["lettuce", "brushed teeth", "work"],
        "squirrel": false
    },
    {
        "events": ["carrot", "ice cream", "brushed teeth", "cycling", "work"],
        "squirrel": false
    },
    {
        "events": ["pizza", "brushed teeth", "work"],
        "squirrel": false
    },
    {
        "events": ["spaghetti", "peanuts", "exercise", "weekend"],
        "squirrel": true
    },
    {
        "events": ["bread", "beer", "computer", "weekend", "touched tree"],
        "squirrel": false
    },
    {
        "events": ["brushed teeth", "running", "work"],
        "squirrel": false
    },
    {
        "events": ["lettuce", "peanuts", "brushed teeth", "work", "touched tree"],
        "squirrel": false
    },
    {
        "events": ["lasagna", "brushed teeth", "television", "work"],
        "squirrel": false
    },
    {
        "events": ["cauliflower", "brushed teeth", "running", "work"],
        "squirrel": false
    },
    {
        "events": ["carrot", "brushed teeth", "running", "work"],
        "squirrel": false
    },
    {
        "events": ["carrot", "reading", "weekend"],
        "squirrel": false
    },
    {
        "events": ["carrot", "peanuts", "reading", "weekend"],
        "squirrel": true
    },
    {
        "events": ["potatoes", "brushed teeth", "running", "work"],
        "squirrel": false
    },
    {
        "events": ["lasagna", "ice cream", "work", "touched tree"],
        "squirrel": false
    },
    {
        "events": ["cauliflower", "peanuts", "brushed teeth", "cycling", "work"],
        "squirrel": false
    },
    {
        "events": ["pizza", "brushed teeth", "running", "work"],
        "squirrel": false
    },
    {
        "events": ["lettuce", "brushed teeth", "work"],
        "squirrel": false
    },
    {
        "events": ["bread", "brushed teeth", "television", "weekend"],
        "squirrel": false
    },
    {
        "events": ["cauliflower", "peanuts", "brushed teeth", "weekend"],
        "squirrel": false
    }
];

let typeCnt = new Map()

function cntEvents(events) {
    for (let evt of events) {
        // 不能这样放进去吧
        // if (typeCnt[evt] === undefined) {
        //     typeCnt[evt] = 1
        // } else {
        //     typeCnt[evt]++
        // }

      
        if (typeCnt.get(evt)===undefined) {
            typeCnt.set(evt,1)
        } else {
           
            typeCnt.set(evt, typeCnt.get(evt)+1)
        }
    }
}

function cntEventsOfType(events, typeMap) {
    for (let evt of events) {
        // if (typeMap[evt] === undefined) {
        //     typeMap[evt] = 1
        // } else {
        //     typeMap[evt]++
        // }

        if (typeMap.get(evt)===undefined) {
            typeMap.set(evt,1)
        } else {
           
            typeMap.set(evt, typeMap.get(evt)+1)
        }
    }
}

function sthInLst(sth,lst){
    for(let i of lst){
        if(i===sth){
            return true
        }
    }
    return false
}

let squirrelTrueMap = new Map()
let squirrelFalseMap = new Map()
let pizzaButNotSq = []
for (let jnl of JOURNAL) {
    let events = jnl.events
    // console.log("events");
    // console.log(events);
    cntEvents(events)
    // 'pizza' in events  这种语法 有吗
    if (sthInLst('pizza',events) && jnl.squirrel === false) {
        pizzaButNotSq.push(events)
    }
    if (jnl.squirrel === true) {
        cntEventsOfType(events, squirrelTrueMap)
    }
    if (jnl.squirrel === false) {
        cntEventsOfType(events, squirrelFalseMap)
    }
}


function objToMap(obj){
    return new Map(Object.entries(obj))
 }
 
 function mapToObj(map){
     return Object.fromEntries(map.entries())
 }
 



function findMaxValKey(mp) {

    // js 查看类型
    console.log(typeof mp);
    console.log('和map一样的类型吗');
    console.log(typeof mp === typeof new Map());
    // if (typeof mp === "object") {
    //     mp = objToMap(mp)
    // }
    //   js 遍历 Map
    // https://juejin.cn/post/6844904040472510471


    console.log(mp);
    let max = 0
    let maxKey = null
    for (let [key, value] of mp) {
        console.log(key,value);
        if (max < value) {
            max = value
            maxKey = key
        }

    }

    //方法二：
    // mp.forEach(function (value, key, map) {
    //     // console.log(value)
    //     console.log(key, value);
    //     if (max < value) {
    //         max = value
    //         maxKey = key
    //     }
    // })

    console.log("maxKey");
    console.log(maxKey);

}


function mapSortByVal(map) {
    let arrayObj = Array.from(map);
    arrayObj.sort(function (a, b) {
        return a[1] - b[1]
    })
    // https://blog.csdn.net/xuxiaoyinliu/article/details/89166234
    console.log("arrayObj");
    console.log(arrayObj);
}
// js map sort by val 
// console.log("typeCnt");
// console.log(typeCnt);

findMaxValKey(typeCnt)
console.log("总数排序之后 从小到大");
mapSortByVal(typeCnt)
console.log("吃了`pizza`  但是没有变成 松鼠 的 当天做了哪些事情 `Events`");
console.log(pizzaButNotSq);

console.log("squirrelTrue,squirrelFalse");
console.log({
    squirrelTrue:squirrelTrueMap,
    squirrelFalse:squirrelFalseMap
});